﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml;
using System.IO;

namespace Dracham.Classes
{
    public class Settings
    {
        private XmlDocument xmlSettings;
        
        public Settings(string fileName)
        {
            if (!File.Exists(fileName))
                throw new FileNotFoundException("Unable to locate: " + fileName);

            this.xmlSettings = new XmlDocument();
            this.xmlSettings.Load(fileName);
        }

        public string this[string key]
        {
            get
            {
                XmlNodeList nodes = this.xmlSettings.GetElementsByTagName(key);

                if (nodes.Count == 0) return null;

                return nodes[0].FirstChild.Value;
            }
        }

        public int GetInteger(string key)
        {
            String str = this[key];

            if (String.IsNullOrEmpty(str)) return 0;

            return Convert.ToInt32(str);
        }

        public double GetDouble(string key)
        {
            String str = this[key];

            if (String.IsNullOrEmpty(str)) return 0;

            return Convert.ToDouble(str);
        }

        public bool GetBoolean(string key)
        {
            String str = this[key];

            if (String.IsNullOrEmpty(str)) return false;

            return Convert.ToBoolean(str);
        }
    }
}
